package com.suke.czx.modules.examstack.controller;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import com.suke.czx.modules.examstack.entity.User2RoleEntity;
import com.suke.czx.modules.examstack.service.User2RoleService;
import com.suke.czx.common.utils.PageUtils;
import com.suke.czx.common.utils.Query;
import com.suke.czx.common.utils.R;




/**
 * 
 * 
 * @author Larry
 * @email lawhw@163.com
 * @date 2018-11-01 23:17:48
 */
@RestController
@RequestMapping("/exam/user2role")
public class User2RoleController {
    @Autowired
    private User2RoleService user2RoleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("exam:user2role:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<User2RoleEntity> user2RoleList = user2RoleService.queryList(query);
        int total = user2RoleService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(user2RoleList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    @RequiresPermissions("exam:user2role:info")
    public R info(@PathVariable("userId") Integer userId){
			User2RoleEntity user2Role = user2RoleService.queryObject(userId);

        return R.ok().put("user2Role", user2Role);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("exam:user2role:save")
    public R save(@RequestBody User2RoleEntity user2Role){
			user2RoleService.save(user2Role);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("exam:user2role:update")
    public R update(@RequestBody User2RoleEntity user2Role){
			user2RoleService.update(user2Role);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("exam:user2role:delete")
    public R delete(@RequestBody Integer[] userIds){
			user2RoleService.deleteBatch(userIds);

        return R.ok();
    }
	
}
